package com.imooc.demo.pingshu;

import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.seimicrawler.xpath.JXDocument;
import org.seimicrawler.xpath.JXNode;

import java.io.IOException;
import java.util.List;

//@SpringBootApplication
public class DetailListThread extends  Thread{

	private final String url;

	public static void log(String log){
		System.out.println("log-> "+log );
	}

	public static final String  host = "https://www.pingshu365.com/ps/9522.html";



	public DetailListThread(String spliderUrl){
		this.url = spliderUrl;
	}


	@Override
	public void run() {
		super.run();

		Document doc = null;
		try {
			doc = Jsoup.connect(host)
                    .header("Accept", "*/*")
                    .header("Accept-Encoding", "gzip, deflate")
                    .header("Accept-Language", "zh-CN,zh;q=0.8,en-US;q=0.5,en;q=0.3")
                    .header("Content-Type", "application/json;charset=UTF-8")
                    .header("User-Agent", "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:48.0) Gecko/20100101 Firefox/48.0")
                    .timeout(10000).ignoreContentType(true).get();
		} catch (IOException e) {
			e.printStackTrace();
		}

		JXDocument jxDocument = JXDocument.create(doc);

		List<JXNode> jxNodes = jxDocument.selN("//div[@class='PD']/ul/li");


		for (JXNode node :jxNodes) {

			log(node.toString());

			// title
			log(node.sel("//a[1]/text()").get(0).asString());
			//// href
			log(SpliderApplication.host+ node.sel("//a[1]/@href").get(0).asString());


		}




	}




}
